package com.itheima.controller;


import com.itheima.entry.PageResult;
import com.itheima.entry.QueryPageBean;
import com.itheima.entry.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jshstart
 * @creat 2020-11-23 9:44
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Reference
    private MenuService menuService;
    @PostMapping("/queryAllByPage")
    public PageResult queryAllByPage(@RequestBody QueryPageBean queryPageBean){
        return menuService.queryAllByPage(queryPageBean);
    }
    @PostMapping("/save")
    public void save(@RequestBody Menu menu){
        menuService.saveOrUpdate(menu);
    }
    @GetMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") Long id){
        menuService.deleteById(id);
    }
    @GetMapping("/findAllMenu")
    public List<Menu> findAllMenu() {
        return menuService.findAllMenu();
    }
    @GetMapping("findMenu")
    public Result findMenu(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String name = authentication.getName();
        return new Result(menuService.findMenu(name));

    }

}
